
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <functional>
#include <numeric>
#include <TClonesArray.h>
#include <TRefArray.h>
#include <TMath.h>

#include <TSystem.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TF1.h>
#include <TH1.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TFile.h>
#include <TChain.h>
#include <TClonesArray.h>
#include <TTree.h>
#include "TDirectory.h"
#include "TAxis.h"
#include "TCanvas.h"
#include "TLorentzVector.h"
#include "TVector3.h"
#include "TString.h"
#include <TLegend.h>
#include "TLine.h"

using namespace std;
using std::cout;
using std::endl;


int GLOB_i = 0;
int GLOB_LISTADDER = 0;
int GLOB_LIST[100] = { 0 };  

int GLOB_VTX = 0;
int GLOB_FGD = 0;
int GLOB_MEC = 0;
int GLOB_MEC_FGD = 0;
int GLOB_NOTMEC = 0;
int GLOB_NOTMEC_FGD = 0;

double pi = TMath::Pi();

int analysis(TString filename="prod5_analysis.list", TString outSaveFolder="/plots/"){

	TFile *f = new TFile(filename);
	f->GetListOfKeys();
	
//	f.ls();

	TH1D* ReconTargetMassFromP_MEC = (TH1D*)f->Get("ReconTargetMassFromP_MEC");
	TH1D* EnuRecHistFromP_NotMEC = (TH1D*)f->Get("EnuRecHistFromP_NotMEC");
	TH1D* EnuRecHistFromP_NotMEC_t = (TH1D*)f->Get("EnuRecHistFromP_NotMEC_t");
	TH1D* FGDnuEHist = (TH1D*)f->Get("FGDnuEHist");
	TH1D* mnAngleHistInFGD_NotMEC = (TH1D*)f->Get("mnAngleHistInFGD_NotMEC");
	TH1D* mPHistInFGD = (TH1D*)f->Get("mPHistInFGD");
	TH1D* pPHistInFGD_NotMEC = (TH1D*)f->Get("pPHistInFGD_NotMEC");
	TH1D* pPHistAfterCuts_NotMEC = (TH1D*)f->Get("pPHistAfterCuts_NotMEC");
	TH1D* pPHistAfterCuts_MEC = (TH1D*)f->Get("pPHistAfterCuts_MEC");
	TH1D* difP_tHistInFGD_NotMEC_t = (TH1D*)f->Get("difP_tHistInFGD_NotMEC_t");
	TH1D* difP_tHistInFGD_NotMEC = (TH1D*)f->Get("difP_tHistInFGD_NotMEC");
	TH1D* difP_tHistInFGD = (TH1D*)f->Get("difP_tHistInFGD");
	TH1D* difP_tHistInFGD_t = (TH1D*)f->Get("difP_tHistInFGD_t");
	TH1D* deltaPhiPt = (TH1D*)f->Get("deltaPhiPt");
	TH1D* deltaPhiPt_t = (TH1D*)f->Get("deltaPhiPt_t");
	TH1D* deltaPhiPt_NotMEC_t = (TH1D*)f->Get("deltaPhiPt_NotMEC_t");
	TH1D* deltaPhiPt_NotMEC = (TH1D*)f->Get("deltaPhiPt_NotMEC");
	

	//pPHistAfterCuts_MEC->Draw();

	//getchar();
	
	
	THStack hs("hs","Stacked Proton Momentum Before Cuts By Channel");
	pPHistBeforeCuts_OTHER->SetFillColor(kGreen);
	hs.Add(pPHistBeforeCuts_OTHER);
	pPHistBeforeCuts_RES->SetFillColor(kOrange);
	hs.Add(pPHistBeforeCuts_RES);
	pPHistBeforeCuts_MEC->SetFillColor(kBlue);
	hs.Add(pPHistBeforeCuts_MEC);
	pPHistBeforeCuts_CCQE->SetFillColor(kRed);
	hs.Add(pPHistBeforeCuts_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg = new TLegend(0.7,0.7,0.9,0.9);
	leg->AddEntry(pPHistBeforeCuts_CCQE,"CCQE","f");
	leg->AddEntry(pPHistBeforeCuts_MEC,"MEC","f");
	leg->AddEntry(pPHistBeforeCuts_RES,"RES","f");
	leg->AddEntry(pPHistBeforeCuts_OTHER,"OTHER","f");
	leg->Draw();
	stackTest->SaveAs(outSaveFolder+"StackProtonBackgroundBreakDownBeforeCuts.gif");
	
	THStack hs("hs","Stacked Proton Momentum After Cuts By Channel");
	pPHistAfterCuts_OTHER->SetFillColor(kGreen);
	hs.Add(pPHistAfterCuts_OTHER);
	pPHistAfterCuts_RES->SetFillColor(kOrange);
	hs.Add(pPHistAfterCuts_RES);
	pPHistAfterCuts_MEC->SetFillColor(kBlue);
	hs.Add(pPHistAfterCuts_MEC);
	pPHistAfterCuts_CCQE->SetFillColor(kRed);
	hs.Add(pPHistAfterCuts_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg->Draw();
	stackTest->SaveAs(outSaveFolder+"StackProtonBackgroundBreakDownAfterCuts.gif");

	THStack hs("hs","Stacked Muon Momentum Before Cuts By Channel");
	mPHistBeforeCuts_OTHER->SetFillColor(kGreen);
	hs.Add(mPHistBeforeCuts_OTHER);
	mPHistBeforeCuts_RES->SetFillColor(kOrange);
	hs.Add(mPHistBeforeCuts_RES);
	mPHistBeforeCuts_MEC->SetFillColor(kBlue);
	hs.Add(mPHistBeforeCuts_MEC);
	mPHistBeforeCuts_CCQE->SetFillColor(kRed);
	hs.Add(mPHistBeforeCuts_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg->Draw();
	stackTest->SaveAs(outSaveFolder+"StackMuonBackgroundBreakDownBeforeCuts.gif");
	
	THStack hs("hs","Stacked Muon Momentum After Cuts By Channel");
	mPHistAfterCuts_OTHER->SetFillColor(kGreen);
	hs.Add(mPHistAfterCuts_OTHER);
	mPHistAfterCuts_RES->SetFillColor(kOrange);
	hs.Add(mPHistAfterCuts_RES);
	mPHistAfterCuts_MEC->SetFillColor(kBlue);
	hs.Add(mPHistAfterCuts_MEC);
	mPHistAfterCuts_CCQE->SetFillColor(kRed);
	hs.Add(mPHistAfterCuts_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg->Draw();
	stackTest->SaveAs(outSaveFolder+"StackMuonBackgroundBreakDownAfterCuts.gif");
		
	THStack hs("hs","Stacked deltaPhi distribution by channel");
	deltaPhiPt_OTHER->SetFillColor(kGreen);
	hs.Add(deltaPhiPt_OTHER);
	deltaPhiPt_RES->SetFillColor(kOrange);
	hs.Add(deltaPhiPt_RES);
	deltaPhiPt->SetFillColor(kBlue);
	hs.Add(deltaPhiPt);
	deltaPhiPt_CCQE->SetFillColor(kRed);
	hs.Add(deltaPhiPt_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg->Draw();
	stackTest->SaveAs(outSaveFolder+"StackDeltaPhiReactionComp.gif");

	THStack hs("hs","Stacked deltaPhi distribution by channel no CCQE");
	deltaPhiPt_OTHER->SetFillColor(kGreen);
	hs.Add(deltaPhiPt_OTHER);
	deltaPhiPt_RES->SetFillColor(kOrange);
	hs.Add(deltaPhiPt_RES);
	deltaPhiPt->SetFillColor(kBlue);
	hs.Add(deltaPhiPt);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	stackTest->SaveAs(outSaveFolder+"StackDeltaPhiReactionCompNoCCQE.gif");
	
	THStack hs("hs","Stacked recon target mass distribution by channel");
	ReconTargetMassFromP_OTHER->SetFillColor(kGreen);
	ReconTargetMassFromP_OTHER->Rebin(2);
	hs.Add(ReconTargetMassFromP_OTHER);
	ReconTargetMassFromP_RES->SetFillColor(kOrange);
	ReconTargetMassFromP_RES->Rebin(2);
	hs.Add(ReconTargetMassFromP_RES);
	ReconTargetMassFromP_MEC->SetFillColor(kBlue);
	ReconTargetMassFromP_MEC->Rebin(2);
	hs.Add(ReconTargetMassFromP_MEC);
	ReconTargetMassFromP_CCQE->SetFillColor(kRed);
	ReconTargetMassFromP_CCQE->Rebin(2);
	hs.Add(ReconTargetMassFromP_CCQE);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	leg->Draw();
	TAxis* xAxis = hs.GetXaxis();
	xAxis->SetRangeUser(-500,2000);
	stackTest->SaveAs(outSaveFolder+"StackTargetMassReactionComp.gif");

	THStack hs("hs","Stacked recon target mass distribution by channel no CCQE");
	ReconTargetMassFromP_OTHER->SetFillColor(kGreen);
	ReconTargetMassFromP_OTHER->Rebin(2);
	hs.Add(ReconTargetMassFromP_OTHER);
	ReconTargetMassFromP_RES->SetFillColor(kOrange);
	ReconTargetMassFromP_RES->Rebin(2);
	hs.Add(ReconTargetMassFromP_RES);
	ReconTargetMassFromP_MEC->SetFillColor(kBlue);
	ReconTargetMassFromP_MEC->Rebin(2);
	hs.Add(ReconTargetMassFromP_MEC);
	TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
	hs.Draw();
	TAxis* xAxis = hs.GetXaxis();
	xAxis->SetRangeUser(-500,2000);
	stackTest->SaveAs(outSaveFolder+"StackTargetMassReactionCompNoCCQE.gif");
  
  
  THStack hs("hs","Stacked proton kT distribution by channel");
  protonKt_OTHER->SetFillColor(kGreen);
  protonKt_OTHER->Rebin(2);
  hs.Add(protonKt_OTHER);
  protonKt_RES->SetFillColor(kOrange);
  protonKt_RES->Rebin(2);
  hs.Add(protonKt_RES);
  protonKt->SetFillColor(kBlue);
  protonKt->Rebin(2);
  hs.Add(protonKt);
  protonKt_CCQE->SetFillColor(kRed);
  protonKt_CCQE->Rebin(2);
  hs.Add(protonKt_CCQE);
  TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
  hs.Draw();
  leg->Draw();
  TAxis* xAxis = hs.GetXaxis();
  xAxis->SetRangeUser(-500,2000);
  stackTest->SaveAs(outSaveFolder+"StackProtonkTReactionComp.gif");

  THStack hs("hs","Stacked proton kT distribution by channel no CCQE");
  protonKt_OTHER->SetFillColor(kGreen);
  protonKt_OTHER->Rebin(2);
  hs.Add(protonKt_OTHER);
  protonKt_RES->SetFillColor(kOrange);
  protonKt_RES->Rebin(2);
  hs.Add(protonKt_RES);
  protonKt->SetFillColor(kBlue);
  protonKt->Rebin(2);
  hs.Add(protonKt);
  TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
  hs.Draw();
  TAxis* xAxis = hs.GetXaxis();
  xAxis->SetRangeUser(-500,2000);
  stackTest->SaveAs(outSaveFolder+"StackProtonkTReactionCompNoCCQE.gif");
  
  THStack hs("hs","Stacked muon kT distribution by channel");
  muonKt_OTHER->SetFillColor(kGreen);
  muonKt_OTHER->Rebin(2);
  hs.Add(muonKt_OTHER);
  muonKt_RES->SetFillColor(kOrange);
  muonKt_RES->Rebin(2);
  hs.Add(muonKt_RES);
  muonKt->SetFillColor(kBlue);
  muonKt->Rebin(2);
  hs.Add(muonKt);
  muonKt_CCQE->SetFillColor(kRed);
  muonKt_CCQE->Rebin(2);
  hs.Add(muonKt_CCQE);
  TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
  hs.Draw();
  leg->Draw();
  TAxis* xAxis = hs.GetXaxis();
  xAxis->SetRangeUser(-500,2000);
  stackTest->SaveAs(outSaveFolder+"StackMuonkTReactionComp.gif");

  THStack hs("hs","Stacked muon kT distribution by channel no CCQE");
  muonKt_OTHER->SetFillColor(kGreen);
  muonKt_OTHER->Rebin(2);
  hs.Add(muonKt_OTHER);
  muonKt_RES->SetFillColor(kOrange);
  muonKt_RES->Rebin(2);
  hs.Add(muonKt_RES);
  muonKt->SetFillColor(kBlue);
  muonKt->Rebin(2);
  hs.Add(muonKt);
  TCanvas *stackTest = new TCanvas("stackTest", "stackTest", 9, 53, 700, 502);
  hs.Draw();
  TAxis* xAxis = hs.GetXaxis();
  xAxis->SetRangeUser(-500,2000);
  stackTest->SaveAs(outSaveFolder+"StackMuonkTReactionCompNoCCQE.gif");

	
	TCanvas *cbgbdbc = new TCanvas("cbgbdbc", "cbgbdbc", 9, 53, 700, 502);
//	pPHistBeforeCuts_NotMEC->SetLineColor(kBlack);
//	pPHistBeforeCuts_NotMEC->SetFillColor(kBlack);
//	pPHistBeforeCuts_NotMEC->SetFillStyle(3004);
//	pPHistBeforeCuts_NotMEC->Draw("");
	pPHistBeforeCuts_CCQE->SetLineColor(kRed);
// 	pPHistBeforeCuts_CCQE->SetFillColor(kRed);
// 	pPHistBeforeCuts_CCQE->SetFillStyle(3005);
	pPHistBeforeCuts_CCQE->Draw("same");
	pPHistBeforeCuts_RES->SetLineColor(kOrange);
// 	pPHistBeforeCuts_RES->SetFillColor(kOrange);
// 	pPHistBeforeCuts_RES->SetFillStyle(3006);
	pPHistBeforeCuts_RES->Draw("same");
	pPHistBeforeCuts_MEC->SetLineColor(kBlue);
// 	pPHistBeforeCuts_MEC->SetFillColor(kBlue);
// 	pPHistBeforeCuts_MEC->SetFillStyle(3003);
	pPHistBeforeCuts_MEC->Draw("same");
	pPHistBeforeCuts_OTHER->SetLineColor(kGreen);
// 	pPHistBeforeCuts_OTHER->SetFillColor(kGreen);
// 	pPHistBeforeCuts_OTHER->SetFillStyle(3007);
	pPHistBeforeCuts_OTHER->Draw("same");
	cbgbdbc->SaveAs(outSaveFolder+"protonBackgroundBreakDownBeforeCuts.gif");
	
	TCanvas *cbgbdac = new TCanvas("cbgbdac", "cbgbdac", 9, 53, 700, 502);
//	pPHistAfterCuts_NotMEC->SetLineColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillStyle(3004);
//	pPHistAfterCuts_NotMEC->Draw("");
	pPHistAfterCuts_MEC->SetLineColor(kBlue);
// 	pPHistAfterCuts_MEC->SetFillColor(kBlue);
// 	pPHistAfterCuts_MEC->SetFillStyle(3003);
	pPHistAfterCuts_MEC->Draw("same");
	pPHistAfterCuts_RES->SetLineColor(kOrange);
// 	pPHistAfterCuts_RES->SetFillColor(kOrange);
// 	pPHistAfterCuts_RES->SetFillStyle(3006);
	pPHistAfterCuts_RES->Draw("same");
	pPHistAfterCuts_CCQE->SetLineColor(kRed);
// 	pPHistAfterCuts_CCQE->SetFillColor(kRed);
// 	pPHistAfterCuts_CCQE->SetFillStyle(3005);
	pPHistAfterCuts_CCQE->Draw("same");
	pPHistAfterCuts_OTHER->SetLineColor(kGreen);
// 	pPHistAfterCuts_OTHER->SetFillColor(kGreen);
// 	pPHistAfterCuts_OTHER->SetFillStyle(3007);
	pPHistAfterCuts_OTHER->Draw("same");
	cbgbdac->SaveAs(outSaveFolder+"protonBackgroundBreakDownAfterCuts.gif");
	
	TCanvas *cmbgbdbc = new TCanvas("cmbgbdbc", "cmbgbdbc", 9, 53, 700, 502);
//	pPHistBeforeCuts_NotMEC->SetLineColor(kBlack);
//	pPHistBeforeCuts_NotMEC->SetFillColor(kBlack);
//	pPHistBeforeCuts_NotMEC->SetFillStyle(3004);
//	pPHistBeforeCuts_NotMEC->Draw("");
	mPHistBeforeCuts_CCQE->SetLineColor(kRed);
// 	mPHistBeforeCuts_CCQE->SetFillColor(kRed);
// 	mPHistBeforeCuts_CCQE->SetFillStyle(3005);
	mPHistBeforeCuts_CCQE->Draw("same");
	mPHistBeforeCuts_RES->SetLineColor(kOrange);
// 	mPHistBeforeCuts_RES->SetFillColor(kOrange);
// 	mPHistBeforeCuts_RES->SetFillStyle(3006);
	mPHistBeforeCuts_RES->Draw("same");
	mPHistBeforeCuts_MEC->SetLineColor(kBlue);
// 	mPHistBeforeCuts_MEC->SetFillColor(kBlue);
// 	mPHistBeforeCuts_MEC->SetFillStyle(3003);
	mPHistBeforeCuts_MEC->Draw("same");
	mPHistBeforeCuts_OTHER->SetLineColor(kGreen);
// 	mPHistBeforeCuts_OTHER->SetFillColor(kGreen);
// 	mPHistBeforeCuts_OTHER->SetFillStyle(3007);
	mPHistBeforeCuts_OTHER->Draw("same");
	cmbgbdbc->SaveAs(outSaveFolder+"muonBackgroundBreakDownBeforeCuts.gif");
	
	TCanvas *cmbgbdac = new TCanvas("cmbgbdac", "cmbgbdac", 9, 53, 700, 502);
//	pPHistAfterCuts_NotMEC->SetLineColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillStyle(3004);
//	pPHistAfterCuts_NotMEC->Draw("");
	mPHistAfterCuts_CCQE->SetLineColor(kRed);
// 	mPHistAfterCuts_CCQE->SetFillColor(kRed);
// 	mPHistAfterCuts_CCQE->SetFillStyle(3005);
	mPHistAfterCuts_CCQE->Draw("");
	mPHistAfterCuts_MEC->SetLineColor(kBlue);
// 	mPHistAfterCuts_MEC->SetFillColor(kBlue);
// 	mPHistAfterCuts_MEC->SetFillStyle(3003);
	mPHistAfterCuts_MEC->Draw("same");
	mPHistAfterCuts_RES->SetLineColor(kOrange);
// 	mPHistAfterCuts_RES->SetFillColor(kOrange);
// 	mPHistAfterCuts_RES->SetFillStyle(3006);
	mPHistAfterCuts_RES->Draw("same");
	mPHistAfterCuts_OTHER->SetLineColor(kGreen);
// 	mPHistAfterCuts_OTHER->SetFillColor(kGreen);
// 	mPHistAfterCuts_OTHER->SetFillStyle(3007);
	mPHistAfterCuts_OTHER->Draw("same");
	cmbgbdac->SaveAs(outSaveFolder+"muonBackgroundBreakDownAfterCuts.gif");
	
	TCanvas *cDeltaPhiComp = new TCanvas("cDeltaPhiComp", "cDeltaPhiComp", 9, 53, 700, 502);
//	pPHistAfterCuts_NotMEC->SetLineColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillStyle(3004);
//	pPHistAfterCuts_NotMEC->Draw("");
	cDeltaPhiComp->SetLogy();
	deltaPhiPt_CCQE->SetLineColor(kRed);
// 	deltaPhiPt_CCQE->SetFillColor(kRed);
// 	deltaPhiPt_CCQE->SetFillStyle(3005);
	deltaPhiPt_CCQE->Draw("");
	deltaPhiPt->SetLineColor(kBlue);
// 	deltaPhiPt->SetFillColor(kBlue);
// 	deltaPhiPt->SetFillStyle(3003);
	deltaPhiPt->Draw("same");
	deltaPhiPt_RES->SetLineColor(kOrange);
// 	deltaPhiPt_RES->SetFillColor(kOrange);
// 	deltaPhiPt_RES->SetFillStyle(3006);
	deltaPhiPt_RES->Draw("same");
	deltaPhiPt_OTHER->SetLineColor(kGreen);
// 	deltaPhiPt_OTHER->SetFillColor(kGreen);
// 	deltaPhiPt_OTHER->SetFillStyle(3007);
	deltaPhiPt_OTHER->Draw("same");
	cDeltaPhiComp->SaveAs(outSaveFolder+"DeltaPhiReactionComp.gif");
	
	TCanvas *cTargetMassComp = new TCanvas("cTargetMassComp", "cTargetMassComp", 9, 53, 700, 502);
//	pPHistAfterCuts_NotMEC->SetLineColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillColor(kBlack);
//	pPHistAfterCuts_NotMEC->SetFillStyle(3004);
//	pPHistAfterCuts_NotMEC->Draw("");
	cTargetMassComp->SetLogy();
	ReconTargetMassFromP_CCQE->SetLineColor(kRed);
// 	ReconTargetMassFromP_CCQE->SetFillColor(kRed);
// 	ReconTargetMassFromP_CCQE->SetFillStyle(3005);
	ReconTargetMassFromP_CCQE->Draw("same");
	ReconTargetMassFromP_MEC->SetLineColor(kBlue);
// 	ReconTargetMassFromP_MEC->SetFillColor(kBlue);
// 	ReconTargetMassFromP_MEC->SetFillStyle(3003);
	ReconTargetMassFromP_MEC->Draw("same");
	ReconTargetMassFromP_RES->SetLineColor(kOrange);
// 	ReconTargetMassFromP_RES->SetFillColor(kOrange);
// 	ReconTargetMassFromP_RES->SetFillStyle(3006);
	ReconTargetMassFromP_RES->Draw("same");

	ReconTargetMassFromP_OTHER->SetLineColor(kGreen);
// 	ReconTargetMassFromP_OTHER->SetFillColor(kGreen);
// 	ReconTargetMassFromP_OTHER->SetFillStyle(3007);
	ReconTargetMassFromP_OTHER->Draw("same");
	cTargetMassComp->SaveAs(outSaveFolder+"TargetMassReactionComp.gif");
	
	
	
	
	TCanvas *c1 = new TCanvas("c1", "c1", 9, 53, 700, 502);
	ReconTargetMass_NotMEC->Scale((1/ReconTargetMass_NotMEC->GetEntries()));
	ReconTargetMass_NotMEC->SetLineColor(kRed);
	ReconTargetMass_NotMEC->Draw();
	ReconTargetMass_MEC->Scale((1/ReconTargetMass_MEC->GetEntries()));
	ReconTargetMass_MEC->Draw("same");
	c1->SaveAs(outSaveFolder+"ReconMassComp.gif");
	
	TCanvas *c1_t = new TCanvas("c1_t", "c1_t", 9, 53, 700, 502);
	ReconTargetMass_NotMEC_t->Scale((1/ReconTargetMass_NotMEC_t->GetEntries()));
	ReconTargetMass_NotMEC_t->SetLineColor(kRed);
	ReconTargetMass_NotMEC_t->Draw();
	ReconTargetMass_MEC_t->Scale((1/ReconTargetMass_MEC_t->GetEntries()));
	ReconTargetMass_MEC_t->Draw("same");
	c1_t->SaveAs(outSaveFolder+"ReconMassComp_t.gif");
	
	TCanvas *c1b = new TCanvas("c1b", "c1b", 9, 53, 700, 502);
	ReconTargetMassFromP_NotMEC->Scale((1/ReconTargetMassFromP_NotMEC->GetEntries()));
	ReconTargetMassFromP_NotMEC->SetLineColor(kRed);
	ReconTargetMassFromP_NotMEC->Draw();
	ReconTargetMassFromP_MEC->Scale((1/ReconTargetMassFromP_MEC->GetEntries()));
	ReconTargetMassFromP_MEC->Draw("same");
	c1b->SaveAs(outSaveFolder+"ReconMassCompFromP.gif");
	
	TCanvas *c1b_t = new TCanvas("c1b_t", "c1b_t", 9, 53, 700, 502);
	ReconTargetMassFromP_NotMEC_t->Scale((1/ReconTargetMassFromP_NotMEC_t->GetEntries()));
	ReconTargetMassFromP_NotMEC_t->SetLineColor(kRed);
	ReconTargetMassFromP_NotMEC_t->Draw();
	ReconTargetMassFromP_MEC_t->Scale((1/ReconTargetMassFromP_MEC_t->GetEntries()));
	ReconTargetMassFromP_MEC_t->Draw("same");
	c1b_t->SaveAs(outSaveFolder+"ReconMassCompFromP_t.gif");
	
	TCanvas *c2 = new TCanvas("c2", "c2", 9, 53, 700, 502);
	EnuRecHist_NotMEC->Scale((1/EnuRecHist_NotMEC->GetEntries()));
	EnuRecHist_NotMEC->SetLineColor(kRed);
	EnuRecHist_NotMEC->Draw();
	EnuRecHist->Scale((1/EnuRecHist->GetEntries()));
	EnuRecHist->Draw("same");
	c2->SaveAs(outSaveFolder+"EnuFromKineComp.gif");
	
	TCanvas *c2_t = new TCanvas("c2_t", "c2_t", 9, 53, 700, 502);
	EnuRecHist_NotMEC_t->Scale((1/EnuRecHist_NotMEC_t->GetEntries()));
	EnuRecHist_NotMEC_t->SetLineColor(kRed);
	EnuRecHist_NotMEC_t->Draw();
	EnuRecHist_t->Scale((1/EnuRecHist_t->GetEntries()));
	EnuRecHist_t->Draw("same");
	c2_t->SaveAs(outSaveFolder+"EnuFromKineComp.gif");
	
	TCanvas *c2b = new TCanvas("c2b", "c2b", 9, 53, 700, 502);
	EnuRecHistFromP_NotMEC->Scale((1/EnuRecHistFromP_NotMEC->GetEntries()));
	EnuRecHistFromP_NotMEC->SetLineColor(kRed);
	EnuRecHistFromP_NotMEC->Draw();
	EnuRecHistFromP->Scale((1/EnuRecHist->GetEntries()));
	EnuRecHistFromP->Draw("same");
	c2b->SaveAs(outSaveFolder+"EnuFromKineComp_P.gif");
	
	TCanvas *c2b_t = new TCanvas("c2b_t", "c2b_t", 9, 53, 700, 502);
	EnuRecHistFromP_NotMEC_t->Scale((1/EnuRecHistFromP_NotMEC_t->GetEntries()));
	EnuRecHistFromP_NotMEC_t->SetLineColor(kRed);
	EnuRecHistFromP_NotMEC_t->Draw();
	EnuRecHistFromP_t->Scale((1/EnuRecHistFromP_t->GetEntries()));
	EnuRecHistFromP_t->Draw("same");
	c2b_t->SaveAs(outSaveFolder+"EnuFromKineComp_P_t.gif");
	
	TCanvas *c2b2 = new TCanvas("c2b2", "c2b2", 9, 53, 700, 502);
	EnuRecHistFromP_NotMEC->Scale((1/EnuRecHistFromP_NotMEC->GetEntries()));
	EnuRecHistFromP_NotMEC->SetLineColor(kRed);
	EnuRecHistFromP_NotMEC->Draw();
	FGDnuEHist->Scale((1/FGDnuEHist->GetEntries()));
	FGDnuEHist->Draw("same");
	c2b2->SaveAs(outSaveFolder+"EnuFromPToTruthCompNotMEC.gif");
	
	TCanvas *c2b2_t = new TCanvas("c2b2_t", "c2b2_t", 9, 53, 700, 502);
	EnuRecHistFromP_NotMEC_t->Scale((1/EnuRecHistFromP_NotMEC_t->GetEntries()));
	EnuRecHistFromP_NotMEC_t->SetLineColor(kRed);
	EnuRecHistFromP_NotMEC_t->Draw();
	FGDnuEHist->Scale((1/FGDnuEHist->GetEntries()));
	FGDnuEHist->Draw("same");
	c2b2_t->SaveAs(outSaveFolder+"EnuFromPToTruthCompNotMEC_t.gif");
	
	TCanvas *c2c = new TCanvas("c2c", "c2c", 9, 53, 700, 502);
	FGDnuEHist_NotMEC->Scale((1/FGDnuEHist_NotMEC->GetEntries()));
	FGDnuEHist_NotMEC->SetLineColor(kRed);
	FGDnuEHist_NotMEC->Draw();
	FGDnuEHist->Scale((1/FGDnuEHist->GetEntries()));
	FGDnuEHist->Draw("same");
	c2c->SaveAs(outSaveFolder+"EnuFromTruthComp.gif");
	
	TCanvas *c3 = new TCanvas("c3", "c3", 9, 53, 700, 502);
	mnAngleHistInFGD_NotMEC->Scale((1/mnAngleHistInFGD_NotMEC->GetEntries()));
	mnAngleHistInFGD_NotMEC->SetLineColor(kRed);
	mnAngleHistInFGD_NotMEC->Draw();
	mnAngleHistInFGD->Scale((1/mnAngleHistInFGD->GetEntries()));
	mnAngleHistInFGD->Draw("same");
	c3->SaveAs(outSaveFolder+"mnAngleComp.gif");
	
	TCanvas *c4 = new TCanvas("c4", "c4", 9, 53, 700, 502);
	mnAngleHistInFGD_NotMEC->Scale((1/mnAngleHistInFGD_NotMEC->GetEntries()));
	mnAngleHistInFGD_NotMEC->SetLineColor(kRed);
	mnAngleHistInFGD_NotMEC->Draw();
	mPHistInFGD->Scale((1/mPHistInFGD->GetEntries()));
	mPHistInFGD->Draw("same");
	c4->SaveAs(outSaveFolder+"mpComp.gif");
	
	TCanvas *cpmc = new TCanvas("cpmc", "cpmc", 9, 53, 700, 502);
	pPHistInFGD_NotMEC->Scale((1/pPHistInFGD_NotMEC->GetEntries()));
	pPHistBeforeCuts_MEC->SetLineColor(kRed);
	pPHistBeforeCuts_MEC->Draw();
	mPHistInFGD->Scale((1/mPHistInFGD->GetEntries()));
	pPHistAfterCuts_MEC->SetLineColor(kBlue);
	pPHistAfterCuts_MEC->Draw("same");
	cpmc->SaveAs(outSaveFolder+"protMomMECBeforeAfterComp.gif");
		
	TCanvas *cpbg = new TCanvas("cpbg", "cpbg", 9, 53, 700, 502);
	pPHistInFGD_NotMEC->Scale((1/pPHistInFGD_NotMEC->GetEntries()));
	pPHistBeforeCuts_NotMEC->SetLineColor(kRed);
	pPHistBeforeCuts_NotMEC->Draw();
	mPHistInFGD->Scale((1/mPHistInFGD->GetEntries()));
	pPHistAfterCuts_NotMEC->SetLineColor(kBlue);
	pPHistAfterCuts_NotMEC->Draw("same");
	cpbg->SaveAs(outSaveFolder+"protMomBGBeforeAfterComp.gif");
	
	TCanvas *cpb = new TCanvas("cpb", "cpb", 9, 53, 700, 502);
	pPHistInFGD_NotMEC->Scale((1/pPHistInFGD_NotMEC->GetEntries()));
	pPHistBeforeCuts_NotMEC->SetLineColor(kRed);
	pPHistBeforeCuts_NotMEC->Draw();
	mPHistInFGD->Scale((1/mPHistInFGD->GetEntries()));
	pPHistBeforeCuts_MEC->SetLineColor(kBlue);
	pPHistBeforeCuts_MEC->Draw("same");
	cpb->SaveAs(outSaveFolder+"protMomBeforeCuts.gif");
	
	TCanvas *cpa = new TCanvas("cpa", "cpa", 9, 53, 700, 502);
	pPHistAfterCuts_NotMEC->Scale((1/pPHistAfterCuts_NotMEC->GetEntries()));
	pPHistAfterCuts_NotMEC->SetLineColor(kRed);
	pPHistAfterCuts_NotMEC->Draw();
	pPHistAfterCuts_MEC->Scale((1/pPHistAfterCuts_MEC->GetEntries()));
	pPHistAfterCuts_MEC->SetLineColor(kBlue);
	pPHistAfterCuts_MEC->Draw("same");
	cpa->SaveAs(outSaveFolder+"protMomAfterCuts.gif");
	
	
	TCanvas *c5_ns = new TCanvas("c5_ns", "c5_ns", 9, 53, 700, 502);
	c5_ns->SetLogy();
	difP_tHistInFGD_NotMEC->SetLineColor(kRed);
	difP_tHistInFGD_NotMEC->Draw();
	difP_tHistInFGD->Draw("same");
	c5_ns->SaveAs(outSaveFolder+"ptComp.gif_ns");
	
	TCanvas *c5_t_ns = new TCanvas("c5_ns", "c5_ns", 9, 53, 700, 502);
	c5_t_ns->SetLogy();
	difP_tHistInFGD_NotMEC_t->SetLineColor(kRed);
	difP_tHistInFGD_NotMEC_t->Draw();
	difP_tHistInFGD_t->Draw("same");
	c5_t_ns->SaveAs(outSaveFolder+"ptComp_t_ns.gif");
	
	TCanvas *c6_ns = new TCanvas("c6_ns", "c6_ns", 9, 53, 700, 502);
	c6_ns->SetLogy();
	deltaPhiPt_NotMEC->SetLineColor(kRed);
	deltaPhiPt_NotMEC->Draw();
	deltaPhiPt->Draw("same");
	c6_ns->SaveAs(outSaveFolder+"deltaPhiComp_ns.gif");
	
	TCanvas *c6_t_ns = new TCanvas("c6_t_ns", "c6_t_ns", 9, 53, 700, 502);
	c6_t_ns->SetLogy();
	deltaPhiPt_NotMEC_t->SetLineColor(kRed);
	deltaPhiPt_NotMEC_t->Draw();
	deltaPhiPt_t->Draw("same");
	c6_t_ns->SaveAs(outSaveFolder+"deltaPhiComp_t_ns.gif");
	
	TCanvas *c5 = new TCanvas("c5", "c5", 9, 53, 700, 502);
	difP_tHistInFGD_NotMEC->Scale((1/difP_tHistInFGD_NotMEC->GetEntries()));
	difP_tHistInFGD_NotMEC->SetLineColor(kRed);
	difP_tHistInFGD_NotMEC->Draw();
	difP_tHistInFGD->Scale((1/difP_tHistInFGD->GetEntries()));
	difP_tHistInFGD->Draw("same");
	c5->SaveAs(outSaveFolder+"ptComp.gif");
	
	TCanvas *c5_t = new TCanvas("c5_t", "c5_t", 9, 53, 700, 502);
	difP_tHistInFGD_NotMEC_t->Scale((1/difP_tHistInFGD_NotMEC_t->GetEntries()));
	difP_tHistInFGD_NotMEC_t->SetLineColor(kRed);
	difP_tHistInFGD_NotMEC_t->Draw();
	difP_tHistInFGD_t->Scale((1/difP_tHistInFGD_t->GetEntries()));
	difP_tHistInFGD_t->Draw("same");
	c5_t->SaveAs(outSaveFolder+"ptComp_t.gif");
	
	TCanvas *c6 = new TCanvas("c6", "c6", 9, 53, 700, 502);
	deltaPhiPt_NotMEC->Scale((1/deltaPhiPt_NotMEC->GetEntries()));
	deltaPhiPt_NotMEC->SetLineColor(kRed);
	deltaPhiPt_NotMEC->Draw();
	deltaPhiPt->Scale((1/deltaPhiPt->GetEntries()));
	deltaPhiPt->Draw("same");
	c6->SaveAs(outSaveFolder+"deltaPhiComp.gif");
	
	TCanvas *c6_t = new TCanvas("c6_t", "c6_t", 9, 53, 700, 502);
	deltaPhiPt_NotMEC_t->SetLineColor(kRed);
	deltaPhiPt_NotMEC_t->Draw();
	deltaPhiPt_t->Draw("same");
	c6_t->SaveAs(outSaveFolder+"deltaPhiComp_t.gif");
	
} 





